<?
$ingame = $this->session->userdata('ingame');
$deltager = $this->session->userdata('deltager');
//print_r($deltager);
//print_r($ingame);
?>


<div class="row-fluid">

	<div class="span6">
		
<?		if($ingame['ingame_id']  == -1) {
		$sideadmin = array('overskrift' => "ADMINISTRATOR",
							'manchet_type' => 'rubrik',
							'manchet_tekst' => "DU er logget ins som administratoor af bogen",
							'rediger_url' => "", 
							'content_headline' => "",
							'content' => array("toc/left/admin"),
						);	

			$this->load->view("includes/manchet",$sideadmin);
	
		}


		$hovedpersoner = array('overskrift' => "HOVEDPERSONER",
							'manchet_type' => 'rubrik',
							'manchet_tekst' => "Du spiller disse karakterer",
							'rediger_url' => "", 
							'content_headline' => "",
							'content' => array("toc/left/player_characters"),
						);	

			$this->load->view("includes/manchet",$hovedpersoner);

		$gm = new gamemaster_model();
		$gm->find_kampagner($deltager['userid']);
		if(!empty($gm->kampagner)) {
			$gm_info = "Du er gamemaster for kampagnerne herunder. Du kan oprette sessioner og invitere rollespillere.";
		}
		else { $gm_info = "Du er ikke gamemaster."; }

		$gamemaster = array('overskrift' => "GAMEMASTER I FØLGENDE KAMPAGNER",
							'manchet_type' => 'rubrik',
							'manchet_tekst' => $gm_info,
							'rediger_url' => "", 
							'content_headline' => "",
							'content' => array("toc/left/gamemastered_campaigns"),
						);	

			$this->load->view("includes/manchet",$gamemaster);


		/*	$forvaltede_sider = array('overskrift' => "FORVALTEDE SIDER",
							'manchet_type' => 'rubrik',
							'manchet_tekst' => "Du har ret og pligt til at redigere og vedligeholde disse sider i bogen",
							'rediger_url' => "", 
							'content_headline' => "",
							'content' => array("toc/left/forvaltede_sider"),
						);	

			$this->load->view("includes/manchet",$forvaltede_sider);*/

?>


	</div>

	<div class="span6" >

		<div id="chosen_campaign">
<?




$rollespiller = new rollespiller();
$rollespiller->find_pcer($deltager['userid']);
$pcer = $rollespiller->pcer;

$gm = new gamemaster_model();
$gm->find_kampagner($deltager['userid']);
$kampagner = $gm->kampagner;


			echo "<div id='admin_boks_new_camp' style='display:none;'>";
				//echo "Opret ny kampagne";
				$this->load->view("forms/opret_kampagne_form");
			echo "</div>";
			
			echo "<div id='admin_boks_all_camp' style='display:none;'>";
				echo "Alle kampagner";
			echo "</div>";
			
			echo "<div id='admin_boks_all_rpg_sessions' style='display:none;'>";
				echo "Alle Sessioner";
			echo "</div>";

			echo "<div id='admin_boks_all_users' style='display:none;'>";
				$this->load->view("toc/left/admin_users");
			echo "</div>";
			
			echo "<div id='admin_boks_new_pc' style='display:none;'>";
				echo "Opret en ny PC";
			echo "</div>";
			


		/*	
			}
			
			if(!empty($kampagner)) {
				
			}*/
			
			
				foreach($pcer as $p) {				
					$campaign = new kampagne();
					$campaign->find_sessions($p['kampagne_id']);					
					$sessions = $campaign->sessions;
					$pc_vis = "none";
					if($ingame['ingame_id'] != 0) {
						if($p['pc_id'] == $ingame['ingame_id']) {
							$pc_vis = "block";
						}
					}
					echo "<div id='kampagne".$p['pc_id']."' style='display:".$pc_vis.";'>";
					/*$sessions_by_pc = array(
							'overskrift' => $p['pc_navn'],
							'manchet_type' => 'ink',
							'manchet_tekst' => "i ".anchor("almanak/side/".$p['kampagne_id'],$p['kampagne_navn'],"class='ink'"),
							'rediger_url' => "", 
							'content_headline' => "",
							'content_data' => array('p' => $p),
							'content' => array("toc/left/sessions_by_pc"),
						);	

			$this->load->view("includes/manchet",$sessions_by_pc);*/


					echo anchor("almanak/side/".$p['pc_id'],"<h1>".$p['pc_navn']."</h1>","class='ink'");
					
					echo "<div style='border:1px black solid;padding:5px;'>";

					if($p['kampagne_id']  != 0) {	
						echo "<h3 class='rubrik'>i ".anchor("almanak/side/".$p['kampagne_id'],$p['kampagne_navn'],"class='ink'")."</h3>";
						
					
					$campaign->find_deltagere($sessions[0]['id']);
					$karakterer = $campaign->deltagere_individer;
					$karakterer_ny = array();

						foreach($karakterer as $r)
						{
								$element2 = new player_character();
								$element2->find_rollespiller($r['id']);	

								$karakterer_ny[] = array
								(
									'karakter' => $r['navn'],
									'id' => $r['id'],
									'rollespiller' => $element2->rollespiller,
									'id_rollespiller' => $element2->id_rollespiller
								);		
								
						}
					//$data['rollespillere'] = $karakterer_ny;
					$next_session_data = array(
							'rollespillere' => $karakterer_ny,
							"kampagne_id" => $p['kampagne_id'],
							"player_character_id" => $p['pc_id'],
							"player_character_navn" => $p['pc_navn'],
							"next_session_name" => $sessions[0]['navn'],
							"next_session_id" => $sessions[0]['id'],
							"next_session_offgame_start" => $sessions[0]['offgame_start'],
							"next_session_offgame_slut" => $sessions[0]['offgame_slut'],
						);

						$this->load->view("forms/tilmeld_session_form",$next_session_data);
					}
					else {

					echo form_open('core/opret/element_kampagne_relation');						
					echo "<h3 class='rubrik'>Er ikke tilmeldt nogen kampagne</h3> <input type='submit' class='rubrik' value='Meld ".$p['pc_navn']." til '>";	
					//echo "<div id='apply_holder' style='display:block;' >";
		

						echo form_dropdown('id_kampagne', $alle_kampagner, '30');
						echo form_hidden("id_element",$p['pc_id']);
							
						echo form_close();


						//print_r($alle_kampagner);
					//echo "</div>";

					//$this->load->view("toc/left/apply_for_campaign");	
					}



					echo "</div>";	
					
					echo "<ul class='leaders'>";
					foreach($sessions as $s) {
					
						echo "<li><span><b class='rubrik'>".$s['nummer'].".</b> ".anchor("almanak/side/".$s['id'],$s['navn'],"class='ink'")."</span><span><b class='rubrik'>".$s['id']."</b></span>";

						
					}
					echo "</ul>";	
					echo "</div>";
				}



			//print_r($kampagner);

			if(!empty($kampagner)) {
				foreach($kampagner as $k) {
				$kampagne_vis = "none";
				if($k['kampagne_id'] == $ingame['kampagne_id']) {
					$kampagne_vis = "block";
				}
									
					$campaign = new kampagne();
					$campaign->find_sessions($k['kampagne_id']);					
					$sessions = $campaign->sessions; 
					
					if(!empty($sessions))
					{
						//$numItems = count($data['sessions']) -1;
						$data['naeste_session'] = $sessions[0]['nummer'];
					}
					else
					{
						$data['naeste_session'] = 0;
					}
					echo "<div id='kampagne".$k['kampagne_id']."' style='display:".$kampagne_vis.";'>";
					echo "<h1 class='ink'>".anchor("almanak/side/".$k['kampagne_id'],$k['kampagne_navn'],"class='ink'")."</h1>";
					
					echo "<div style='border:1px black solid;padding:10px;overflow:auto;'>";
						$data = array(
							'kampagne' => $k['kampagne_id'],
							'naeste_session' => $data['naeste_session'],
						);
						//if(!empty($sessions)) {
							if(empty($sessions) or $sessions[0]['offgame_start'] < time()) {
								$this->load->view("forms/opret_session_form",$data);
							}
							else {
								$data = $sessions[0];
								//print_r($data);
								$this->load->view("forms/rediger_session_form",$data);								
								
							}
						//}
					echo "</div>";	
					
					echo "<h2 class='ink'>Sessioner i ".$k['kampagne_navn']."</h2>";					
					echo "<ul class='leaders'>";
					if(count($sessions) > 0) {
						foreach($sessions as $s) {
						
							echo "<li><span><b class='rubrik'>".$s['nummer'].".</b> ".anchor("almanak/side/".$s['id'],$s['navn'],"class='ink'")."</span><span><b class='rubrik'>".date("d-m-Y",$s['offgame_start'])."</b></span>";

						
						}
					}
					else { echo "<p class='rubrik'>Der er ingen sessioner i kampagnen.</p>"; }
					echo "</ul>";	
					echo "</div><br>";
				}
			}
			?>

		
		</div>


		<?//	$this->load->view("forms/opret_session_form"); ?>

	</div>
</div>
